//
//  EmoticonTextAttachment.swift
//  KeyBoard
//
//  Created by mac on 15/12/26.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class EmoticonTextAttachment: NSTextAttachment {

    var chs :String?
    
    func imageTextToText(em:Emoticons,font:UIFont)-> NSAttributedString {
        //走到这点击的是图片
        let image = UIImage(contentsOfFile: em.imagePath ?? "")
        let attachment = EmoticonTextAttachment()
        attachment.image = image
        attachment.chs = em.chs
        //设置行高
        let height = font.lineHeight
        attachment.bounds = CGRect(x: 0, y: -4, width: height, height: height)
        //通过附件来实例化属性文本
        let imageText = NSMutableAttributedString(attributedString: NSAttributedString(attachment: attachment))
        //给属性文本添加属性
        imageText.addAttribute(NSFontAttributeName, value: font, range: NSRange(location: 0, length: 1))
        return imageText;
    }
    
}
